package com.itheima.service.impl;

import com.itheima.common.utils.SMSUtils;
import com.itheima.common.utils.ValidateCodeUtils;
import com.itheima.mapper.ValidatecodeMapper;
import com.itheima.service.ValidatecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
public class ValidatecodeServiceImpl implements ValidatecodeService {

    @Autowired
    private ValidatecodeMapper validatecodeMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 发送短信
     * @param telephone
     */
    public void send(String telephone) {
        ValidateCodeUtils validateCodeUtils = new ValidateCodeUtils();
        Integer code = validateCodeUtils.generateValidateCode(4);
        String code1 = String.valueOf(code);
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(telephone,code1,300);
        SMSUtils.sendMessage(SMSUtils.VALIDATE_CODE,telephone,code1);
    }
}
